#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int eraseOverlapIntervals(vector<vector<int>> &intervals) {
  sort(intervals.begin(), intervals.end(),
       [](const vector<int> &a, const vector<int> &b) {
         if (a[0] == b[0]) {
           return (a[1] - a[0]) < (b[1] - b[0]);
         } else {
           return a[0] < b[0];
         }
       });
  int count = 0;
  for (int i = 1; i < intervals.size(); ++i) {
    if (intervals[i][0] < intervals[i - 1][1]) {
      count++;
      // 删除右边界最大的那个区间
      intervals[i][1] = min(intervals[i - 1][1], intervals[i][1]);
    }
  }
  return count;
}

int main() {
  vector<vector<int>> t = {{-52, 31},  {-73, -26}, {82, 97}, {-65, -11},
                           {-62, -49}, {95, 99},   {58, 95}, {-31, 49},
                           {66, 98},   {-63, 2},   {30, 47}, {-40, -26}};
  int i = eraseOverlapIntervals(t);
  cout << i << endl;
}